import 'package:flutter/material.dart';

class HomeGoods extends StatelessWidget {
  const HomeGoods({super.key, required this.goodsList});

  final List goodsList;

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
        // 处理listview嵌套报错
        shrinkWrap: true,
        // 禁止滚动
        physics: const NeverScrollableScrollPhysics(),
        itemBuilder: (BuildContext context, int index) {
          if (goodsList.isNotEmpty) {
            Map item = goodsList[index];
            return GestureDetector(
                onTap: () {
                  Navigator.pushNamed(context, '/search');
                },
                child: Container(
                  height: 120,
                  color: Colors.red[90],
                  child: Container(
                    padding: const EdgeInsets.all(10),
                    child: Row(
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(right: 8),
                          child: Image.network(
                            '${item['goods_image']}',
                            width: 90,
                          ),
                        ),
                        Expanded(
                            child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: [
                            // 第一行
                            Expanded(
                                child: Text(
                              '${item['goods_name']}',
                              maxLines: 2,
                              overflow: TextOverflow.ellipsis,
                            )),
                            // 第二行
                            Text('已售${item['goods_sales']}件'),
                            // 第三行
                            Row(
                              children: [
                                Text(
                                  '¥${item['goods_price_max']}',
                                  style: const TextStyle(color: Colors.red),
                                ),
                                Padding(
                                  padding: const EdgeInsets.only(left: 3),
                                  child: Text(
                                    '¥${item['line_price_max']}',
                                    style: const TextStyle(
                                        color: Colors.grey,
                                        decoration: TextDecoration.lineThrough),
                                  ),
                                )
                              ],
                            )
                          ],
                        ))
                      ],
                    ),
                  ),
                ));
          }
          return null;
        },
        separatorBuilder: (BuildContext context, int index) {
          return Container(
            margin: const EdgeInsets.only(left: 9, right: 8),
            height: 1,
            color: const Color.fromARGB(255, 210, 209, 209),
          );
        },
        itemCount: goodsList.length);
  }
}
